(function (angular) {
  var module = angular.module("loginApp", []);
  module.controller("loginCtrl", ["$scope", "$http", function ($scope, $http) {
// 初始化
    $scope.loginName = "";
    $scope.loginPwd = "";
    $scope.loginCode = "";
    // 按钮
    $scope.url = "http://127.0.0.1:8080/lx/";
    $scope.logindo = function () {
      layer.load();
      $http({
        method: "post",
        url: $scope.url + "login",
        data: {
          account: $scope.loginName,
          pwd: $scope.loginPwd,
          code: $scope.loginCode
        }
      }).success(function (res) {
        layer.closeAll("loading");
        console.log(res);
        if(res.code===0){
          layer.alert("登录成功");
          window.location.href = 'user.html';
        }else {
          layer.alert("登录失败");
        }
      })
    };
    // 获取验证码:
    $scope.getCode = function () {
      $scope.imgUrl = $scope.url + "getVerify?" + new Date().getMilliseconds();
    }
    $scope.getCode();
  }])
})(angular);
